﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sigil.NonGeneric;

namespace SigilTests
{
	public partial class Multiply
	{
		[TestMethod]
		public void SimpleNonGeneric()
		{
			var e1 = Emit.NewDynamicMethod(typeof(double), new[] { typeof(double), typeof(double) }, "E1");
			e1.LoadArgument(0);
			e1.LoadArgument(1);
			e1.Multiply();
			e1.Return();

			var d1 = e1.CreateDelegate<Func<double, double, double>>();

			Assert.AreEqual(3.14 * 1.59, d1(3.14, 1.59));
		}

		[TestMethod]
		public void OverflowNonGeneric()
		{
			var e1 = Emit.NewDynamicMethod(typeof(double), new[] { typeof(double), typeof(double) }, "E1");
			e1.LoadArgument(0);
			e1.LoadArgument(1);
			e1.MultiplyOverflow();
			e1.Return();

			var d1 = e1.CreateDelegate<Func<double, double, double>>();

			Assert.AreEqual(3.14 * 1.59, d1(3.14, 1.59));
		}

		[TestMethod]
		public void UnsignedOverflowNonGeneric()
		{
			var e1 = Emit.NewDynamicMethod(typeof(double), new[] { typeof(double), typeof(double) }, "E1");
			e1.LoadArgument(0);
			e1.LoadArgument(1);
			e1.UnsignedMultiplyOverflow();
			e1.Return();

			var d1 = e1.CreateDelegate<Func<double, double, double>>();

			Assert.AreEqual(3.14 * 1.59, d1(3.14, 1.59));
		}
	}
}